package main

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"minititok/databases"
	"minititok/middleware"
	"minititok/routes"
	"minititok/utils"
	"time"
)

func main() {
	databases.InitDB()
	r := gin.Default()
	jwtManager := utils.NewJWTManager("AAABBB")

	r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"http://localhost:3000"}, // 你的前端地址
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Authorization"},
		AllowCredentials: true, // 允许发送 cookie/token
		MaxAge:           12 * time.Hour,
	}))
	r.Use(middlewares.Logger())
	r.Use(middlewares.JWTAuthMiddleware(jwtManager))

	routes.SetupRoutes(r)

	r.Run(":8000")
}
